# plp-note-match-fun-times
# Robert Elliott, Chris Smith, Will Flanery

# This is the main program, it is comprised of essentially
# one over-arching loop that calls and runs the audio, video
# and input modules appropriately.

# Define storage location in memory for the program.
.org 0x10000000

# Video framebuffers
fb_1:
.word 0x10f00000

fb_2:
.word 0x10f50000

# Audio buffer
li $t4, 0               #last offset in the buffer

# Jump to the first actual instructions. (Account for branch delay slot)
j start
nop

# Include reference libraries and our vga, audio and input modules.
.include libplp_vga.asm
.include libplp_timer.asm
.include vga_plp_nmft.asm
.include audio_plp_nmft.asm
.include audio_data.asm

# This is the start of the actual program.
# In this routine, we want to basically initialize the VGA and Audio
# modules to a usable state.
start:
	# VGA INITIALIZATION

        # enable the vga module
        jal libplp_vga_enable
        # branch delay slot
        nop

        # framebuffer one, were storing our pixel data here
        li $a0, fb_1
        lw $a0, 0($a0)  # ?
        jal libplp_vga_framebuffer
        nop

        # make background black
        li $a0, 0x00000000
        jal libplp_vga_clear
        nop

	# create a second framebuffer, with the same contents as the first
        li $a0, fb_2
        lw $a0, 0($a0)
        jal libplp_vga_framebuffer
        nop

        # make background black again
        li $a0, 0x00000000
        jal libplp_vga_clear
        nop

        # this remains an arcane mystery unsolved throughout the ages
        li $s0, 0xf0500004      # PLPID RTFM
        lw $s0, 0($s0)

	# AUDIO INITIALIZATION

        li $t0, 0xf0b00000      #i2s position pointer
        li $t1, audio_data      #audio data base

        li $t2, 0               #offset within the audio data
        li $t3, audio_data_end


        li $t5, 0xf0b10000      #i2s buffer base

	# like an audio buffer, touched for the very first time
	jal audio_fill
	nop

	# INPUT INITIALIZATION
	
	# ...to be continued...

# This is the actual main loop of plp-nmft.
# In here is where the cool stuff happens
# We make calls to all of the relevant routines to display
# note prompts on the screen and play cool jamtunes.
loop:
        # if the buffer is empty, refill it
        beq $t6, $zero, audio_fill
        nop
	
	# I think at this point probably start playing audio.
	# Perhaps within audio_play we can implement a break
	# to jump out after so many copies
	jal audio_play
	nop

	# at which point, we might return here, do some check
	# on the audio pitch

	# PSEUDOCODE FOLLOWS
	# if($audio_pointer >= x){
	#	$some_register=y;}

	# After we store some value (probably something like 1-4, depending
	# on how many possible buttons/blocks we want) into some register,
	# we jal to drawblock, which checks that register and draws the
	# appropriate block on the screen.
	# drawblock($some_register);

	# Then obviously we will need to do input stuff.

	# ...next time on csi: plp

	# LOOP IT SUCKA
	j loop
	nop
